﻿using System.Data.Entity;

namespace KurumsalMimari.Entity
{
    public class MsSqlContext : DbContext
    {
        public DbSet<Ders> Dersler { get; set; }
        public DbSet<Ogretmen> Ogretmenler { get; set; }
        public MsSqlContext(string nameOrConnectionString) : base(nameOrConnectionString)
        {
        }

        public MsSqlContext()
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Ogretmen>()
                .HasMany<Ders>(d => d.Dersler)
                .WithMany(o => o.Ogretmenler)
                .Map(od =>
                {
                    od.MapLeftKey("DersId");
                    od.MapRightKey("OgretmenId");
                    od.ToTable("DersOgretmenEsleme");
                });
            base.OnModelCreating(modelBuilder);
        }
    }
}